import {defineStore} from 'pinia'
import {editImage, login, personAllOrCollectWork, personInfo, register} from '@/service/index.js'
import {getLocalStore} from '@/utils/localUser.js'

const useLoginStore = defineStore('login', {
    state: () => ({
        userInfo: getLocalStore('userInfo') ?? '',
        token: getLocalStore('token') ?? '',
        isShow: false,
        info: '立即登录',
        articleInfoList: "",
        personInfo: "",
        searchParam: "",
        type: ""
    }),
    actions: {
        //登录
        async loginAction(loginParams) {
            const res = await login(loginParams)
            this.userInfo = res.data
            return res
        },
        //注册
        async registerAction(loginParams) {
            return await register(loginParams)
        },
        //个人中心信息
        async personInfoAction() {
            const res = await personInfo()
            this.personInfo = res.data
        },
        //个人中心
        async personAllOrCollectWorkAction(page, size, type, param) {
            const res = await personAllOrCollectWork(page, size, type, param)
            this.articleInfoList = res.data
        },
        //修改图片
        async editImageAction(imgUrl) {
            const res = await editImage(imgUrl)
        }
    }
})

export default useLoginStore
